package controllers.weixin;

import auth.WxMpAuth;
import models.constants.Gender;
import models.enums.IssueStatus;
import models.global.Image;
import models.issue.Issue;
import models.user.User;
import play.mvc.Controller;
import play.mvc.With;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@With(WxMpAuth.class)
public class UserController extends Controller {

    public static void index() {
        User user = WxMpAuth.currentUser();
        Object tmp = User.findCampusName(user.id);
        String campusName = tmp != null ? tmp.toString() : "";
        render(user, campusName);
    }

    public static void userInfo(){render();}

    public static void contact(){render();}

    public static void getUser(){
        User user = WxMpAuth.currentUser();
        renderJSON(user);
    }

    public static void saveUser(String realName, String phone, String idCard, Gender gender, Integer age){
        Map<String, Object> resultMap = new HashMap<>();

        User user = WxMpAuth.currentUser();
        user.realName=realName;
        user.phone=phone;
        user.idCard=idCard;
        user.gender=gender;
        user.age=age;
        user.save();

        resultMap.put("success", true);
        resultMap.put("msg", "业主信息提交成功");
        renderJSON(resultMap);
    }

}
